package com.yegs.jltqc.controller;

import com.yegs.jltqc.TO.NamePageQuery;
import com.yegs.jltqc.VO.BaseDepartment;
import com.yegs.jltqc.VO.BaseMenu;
import com.yegs.jltqc.common.StoreException;
import com.yegs.jltqc.config.Msg;
import com.yegs.jltqc.service.BaseDepartmentService;
import com.yegs.jltqc.service.BaseMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/baseDepartment")
public class BaseDepartmentController {

    @Autowired
    private BaseDepartmentService baseDepartmentService;

    @PostMapping("/save")
    public Msg save(@RequestBody BaseDepartment baseDepartment){
        try{
            baseDepartmentService.save(baseDepartment);
            return Msg.success();
        }catch (StoreException e){
            return Msg.error(e.getMessage());
        }
    }
    @GetMapping("/list")
    public Msg list(){
        return Msg.success("list",baseDepartmentService.list());
    }


    @GetMapping("/get")
    public Msg get(@RequestParam Long id){
        return Msg.success("data",baseDepartmentService.get(id));
    }

    @GetMapping("/del")
    public Msg del(@RequestParam Long id){
        baseDepartmentService.del(id);
        return Msg.success();
    }


    @PostMapping("/query")
    public Msg query(@RequestBody NamePageQuery query){
        return Msg.success("page",baseDepartmentService.query(query));
    }



}
